package org.example.flink;

import com.google.gson.Gson;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.io.IOException;
import java.time.LocalTime;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

public class TestDataProduct {

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        Properties props = new Properties();
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
        props.put(ProducerConfig.CLIENT_ID_CONFIG, "TestDataProduct");
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "ha:9092");
        KafkaProducer<String, String> producer = new KafkaProducer<>(props);
        for (int i = 0; i < 10; i++) {
            Person person = new Person(RandomStringUtils.randomAlphanumeric(5), LocalTime.now().toString());
            producer.send(new ProducerRecord<>("my_tpc", new Gson().toJson(person))).get();
        }
    }
}
